var result = [];

$(function(){
    $.ajax({
        type:"get",
        url: basePath + "report/bloodSugarPieReport",
        beforeSend: function(request) {
            request.setRequestHeader("header", localStorage.getItem("token"));
        },
        data:{},
        async:false,
        cache:true,
        dataType: "json", //this is important
        success:function(data) {
                //迭代，把异步获取的数据放到数组中
                $.each(data,function(i,d){
                    result.push([d.name,d.value]);
                });
        },
        error : function(data) {

            alert("error:" + data);
        }
    });

    new Highcharts.chart(
        {
        chart: {
            renderTo : 'bloodSugarPieContainer', // 页面DIV层ID
            type: 'pie',
            options3d: {
                enabled: true,
                alpha: 45,
                beta: 0
            }
        },
            colors: ['#FF0000',  '#1C1C1C','#ADFF2F'],
        title: {
            text: "<div style='text-align: center;font-size: 16px;font-weight: bold;'>最近50次血糖统计[点击图片查看分析结果]</div>"
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                depth: 35,
                dataLabels: {
                    enabled: true,
                    format: '{point.name}'
                },
                events: {
                    click: function (e) {
                        //alert(e.point.name)
                        $.ajax({
                            type:"get",
                            url:basePath + "report/bloodSugarMeasureTimes",
                            beforeSend: function(request) {
                                request.setRequestHeader("header", localStorage.getItem("token"));
                            },
                            cache:false,
                            dataType: "json",
                            success:function(result) {
                                $.messager.alert('信息', result.result,'SUCCESS').window({ width: 500, height: 300 ,top:10,left:200});
                            }
                        });
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: '',
            data: result
        }]
    });
});







